﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Innova.Entites;
using System.Data;

namespace Innova.Repository
{
    public class ReservaRepository : MasterRepository, IReservaRepository
    {
        public List<RESERVA> GetAllReservasByServicioIdAndPatrocinadorId(int IdServ, int idPatro)
        {
            var query = from c in Context.RESERVAs
                        where c.ServicioId.Equals(IdServ) && c.SERVICIO.PatrocinadorId.Equals(idPatro)
                        select c;
            return query.ToList();
        }

        public RESERVA GetFromReservaById(int id)
        {
            var query = from c in Context.RESERVAs
                        where c.Id.Equals(id)
                        select c;
            return query.SingleOrDefault();
        }

        public void AddReserva(RESERVA reserva)
        {
            Context.RESERVAs.Add(reserva);
            Context.SaveChanges();
        }

        public void UpdateReserva(RESERVA reserva)
        {
            Context.RESERVAs.Attach(reserva);
            Context.Entry(reserva).State = EntityState.Modified;
            Context.SaveChanges();
        }
    }
}
